/*
 * Copyright (C) 2009 Otávio Scherer Garcia
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.technorati4j.entity;

import com.googlecode.technorati4j.enums.ResponseFormat;

/**
 * Request entity for dailycounts API.
 * 
 * @author Otávio Scherer Garcia
 * @version $Revision$
 */
public final class DailyCountsRequest
    implements Request {

    /** The Technorati API key. */
    private String key;

    /** Set this to the keyword query. The query should be url-escaped UTF-8. */
    private String q;

    /**
     * Used to specify the number of days in the past to request daily count data for. Can be any integer between 1 and
     * 180, default is 180
     */
    private int days;

    /**
     * Results are returned in XML by default. You may optionally request the results in CSV using a parameter value of
     * csv.
     */
    private ResponseFormat format;

    /**
     * The default constructor.
     */
    public DailyCountsRequest() {
    }

    /**
     * Constructor with mandatory attributes.
     * 
     * @param key The key parameter.
     * @param q The query parameter.
     */
    public DailyCountsRequest(String key, String q) {
        setKey(key);
        setQ(q);
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getQ() {
        return q;
    }

    public void setQ(String q) {
        this.q = q;
    }

    public int getDays() {
        return days;
    }

    public void setDays(int days) {
        this.days = days;
    }

    public ResponseFormat getFormat() {
        return format;
    }

    public void setFormat(ResponseFormat format) {
        this.format = format;
    }

    public String getParameters() {
        final StringBuilder str = new StringBuilder();
        str.append("key=");
        str.append(key);
        str.append("&q=");
        str.append(q);

        if (days > 0 && days <= 180) {
            str.append("&days=");
            str.append(days);
        }

        if (format != null) {
            str.append("&format=");
            str.append(format);
        }

        return str.toString();
    }
}
